package cn.openea.perpartner.meily.web.mapper;

import cn.openea.perpartner.meily.web.entity.Menu;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜单权限表(Menu)表数据库访问层
 *
 * @author Weird077
 * @since 2023-03-15 16:17:56
 */
public interface MenuMapper extends MPJBaseMapper<Menu> {

    @Select("select concat(m.menu_id) as perms " +
            "from meily_menu m " +
            "left join meily_role_menu rm on m.menu_id = rm.menu_id " +
            "where rm.role_id = #{roleId} " +
            "order by m.parent_id, m.order_num")
    List<String> selectMenuTree(Long roleId);
    @Select("SELECT t.menu_id, t.parent_id, t.menu_name, t.order_num, t.url , t.visible, t.icon, t.remark," +
            "(SELECT menu_name FROM meily_menu WHERE menu_id = t.parent_id) parent_name " +
            "FROM meily_menu t " +
            "where t.menu_id = #{menuId}")
    Menu selectMenuById(Long menuId);
    @Select("select distinct m.menu_id, m.parent_id, m.menu_name, m.url, m.visible,m.icon, m.order_num, m.create_time" +
            " from meily_menu m " +
            " left join meily_role_menu rm on m.menu_id = rm.menu_id" +
            " left join meily_user_role ur on rm.role_id = ur.role_id" +
            " left join meily_role ro on ur.role_id = ro.role_id" +
            " where ur.user_id = #{userId}" +
            " order by m.parent_id, m.order_num")
    List<Menu> selectMenuAllByUserId(String userId);
}

